//<SCRIPT LANGUAGE="javascript">
//=================== TreeIE5 =====================//
//________                     ______//
//        intrinsic properties       //
//_lable,_action,_indent,_path,_image//
///////////////////////////////////////
var divTreeIE5Root="divTreeIE5Root";
var SPAN_TREE_IE5_LABLE = "spanTreeIE5Lable";
var SPAN_TREE_IE5_CONTAINER = "spanTreeIE5Container";
var DIV_TREE_IE5_ITEM = "divTreeIE5Item";
var DIV_TREE_IE5_PARENT = "divTreeIE5Parent";
var IMG_IE5_PLUS_MINUS = "imgIE5PlusMinus";
var TREE_NODE = "treeNode";
var TREE_IE5_CURR_NODE = "currNode";
function TreeIE5(params){
	if( typeof(params) == "string" )params = {_lable:params};
	var p;
	for( p in params )
		this[p] = (!defined(params[p])||params[p]!=null?params[p]:'')+'';
	this.addNode = function(params){
		var node = new TreeIE5(params);
		if( !this._nodes )this._nodes = new Array(node);
		else this._nodes[this._nodes.length] = node;
		return node;
	}
	this.draw = function(parentElement,rootName){
		var s='';
		if( this._lable )
			s =  '<div '+noWrap(this._wrap)+'align="left" style="MARGIN-LEFT:'+(isDefined(this._indent)?this._indent:16)+'" + id="'+getID(this)+'">'+
							(this._noPM?'':'<img onclick="toggleTreeIE5(this)" src="/images/TreeIE5/'+drawPlusMinus(this)+'.gif" '+' style="MARGIN-RIGHT:4" onmouseover="this.className=\'raisedPM\'" onmouseout="this.className=\'\'" id="'+IMG_IE5_PLUS_MINUS+'">')+
							'\n<span lable="" class="'+TREE_NODE+'" path="'+this._path+'" onclick="selectTreeIE5Lable(this);'+
										 (this._action||'')+'"'+drawOtherParams(this)+' id="'+SPAN_TREE_IE5_CONTAINER+'"'+
										 (this._oncontextmenu?' oncontextmenu="'+this._oncontextmenu+';return false"':'')+
										 '>'+
								(this._image?'\n<span style="background-color:white"><img src="'+this._image+'" style="MARGIN-RIGHT:4;VERTICAL-ALIGN: bottom"></span>':"")+
								'\n<span id="'+SPAN_TREE_IE5_LABLE+'"'+drawStyle(this._style)+(this._class?" class='"+this._class+"'":"")+
											 (this._classOver?' over="true" classOver="'+this._classOver+'"':'')+
											 (this._oncontextmenu?' oncontextmenu="return false"':'')+
											 '>'+this._lable+'\n</span>' +
							'\n</span>';
		else s = '<div id="'+divTreeIE5Root+'" '+(rootName?'rootName="'+rootName+'" ':'')+'style="MARGIN-LEFT:0">';
		for( var n=0; this._nodes && n < this._nodes.length; n++ )
			s += this._nodes[n].draw();
		s += '\n</div>';
		if( parentElement )parentElement.innerHTML = s;
		else return s;
	}
	//Locals
	function noWrap(wrap){return wrap ? "" : 'nowrap=" " ' }
	function getID(tree){ return isParent(tree)?DIV_TREE_IE5_PARENT:DIV_TREE_IE5_ITEM }
	function drawStyle(style){return style?" style='"+style+"' ":"";}
	function drawPlusMinus(tree){	return isParent(tree)?"Minus1":"Blank1" }
	function isParent(tree){ return tree._nodes && tree._nodes.length?true:false }
	function drawOtherParams(params){
		var p,s = '';
		for( p in params )
			if( isOptional(p,params[p]) )s += ' '+p+'="'+params[p]+'"';
		return s;
	}
	function isOptional(paramName,paramValue){
		return typeof(paramValue)=="string" && !paramName.match(/^_/);
	}
}

function isDefined(v){ return typeof(v)!='undefined' }

function findIE5Lable(lable,rootName,offset){
var root = document.all[(rootName||'').id || divTreeIE5Root];
	var nodes = getIE5LableElements(root);
	if( !nodes[0] )nodes = new Array(nodes);
	for( var i=0; nodes[0] && i < nodes.length; i++ )
		if( !lable || nodes[i].innerText.match(new RegExp("\s*"+lable+"\s*","i")) )nodes = nodes[i+(offset||0)] || nodes[i];
	return nodes[i-1]?null:nodes;
}
function getIE5Root(el){return getParentElementByID(el,divTreeIE5Root)}
function getIE5CurrLableText(parent){
var lable = getIE5CurrLable(parent);
	return !lable?'':lable.innerText;
}
function getIE5CurrLable(parent){
	var node = getIE5CurrNode(parent);
	return !node?null:(node.all[SPAN_TREE_IE5_LABLE][0]||node.all[SPAN_TREE_IE5_LABLE]);
}
function getIE5CurrNode(parent){
	return ((parent||document).all[divTreeIE5Root]||{})[TREE_IE5_CURR_NODE];
}
function selectTreeIE5Lable(el,clear){
var menuRoot = getIE5Root(el);
		if( !menuRoot )return;
		menuRoot[TREE_IE5_CURR_NODE] = el;
var span,eSpans = new Enumerator(menuRoot.all.tags("span"));
		for( ; !eSpans.atEnd(); eSpans.moveNext() ){
			span = eSpans.item();
			if( span.id != SPAN_TREE_IE5_LABLE )continue;
			if( isDefined(span.style.oldColor) && span.style.oldColor != null ){
				span.style.color = span.style.oldColor;
				span.style.oldColor = null;
			}
			if( isDefined(span.style.oldBackgroundColor) && span.style.oldBackgroundColor != null ){
				span.style.backgroundColor = span.style.oldBackgroundColor;
				span.style.oldBackgroundColor = null;
			}
		}
		if( clear )return;
		span = getLableElement(el);
		if( span.length )span = span[0];
		span.style.oldColor = span.style.color;
		span.style.oldBackgroundColor = span.style.backgroundColor;
		span.style.color = "white";
		span.style.backgroundColor = "navy";
}
function getIE5LableElementsArray(parent,re){
	var ls = getIE5LableElements(parent);
	for( var i=0,a=new Array; ls && i < ls.length; i++ )
		if( !re || ls[i].innerText.match(re) )a.push(ls[i].innerText);
	return a;
}
function getIE5LableElements(parent){return parent.all[SPAN_TREE_IE5_LABLE];}
function getIE5LableElement(parent){return getLableElement(parent)}
function getLableElement(parent){
	var l = getIE5LableElements(parent);
	return l[0] || l;
}
function getLableParent(child){ return getParentElementByID(child,SPAN_TREE_IE5_CONTAINER) }
function getTreeParent(child){ return getParentElementByID(child,DIV_TREE_IE5_PARENT) }

function getChildrenByID(parent,id,tagName){
var re = new RegExp("^"+id+"$","i");
var aChildren = new Array();
var eChildren = new Enumerator( (tagName?parent.all.tags(tagName):parent.all) );
		for( ; !eChildren.atEnd(); eChildren.moveNext() )
			if( eChildren.item().id.match(re) )
				aChildren[aChildren.length] = eChildren.item();
		return aChildren;
}

function getParentElementByID(el,id){
var re = new RegExp("^"+id+"$","i");
	for( ; el; el = el.parentElement )
		if( el.id.match(re) || (el.name && el.name.match(re)) )return el;
	return null;
}

function toggleTreeIE5(el,collapse){
	if( !defined(collapse) )collapse = !isCollapsed(el);
	var parent = getParentElementByID(el,DIV_TREE_IE5_PARENT);
	if( !parent )return;
	var divs = parent.children.tags("div");
	var img = (parent.all[IMG_IE5_PLUS_MINUS]||{})[0] || parent[IMG_IE5_PLUS_MINUS];
	for( var d=0; d < divs.length; d++ ){
		divs[d].style.display = collapse?"none":"";
		(img||{}).src = "/images/TreeIE5/"+(collapse?"Plus1":"Minus1")+".gif";
	}
	//locals
	function isCollapsed(el){
		return el.src.match(/plus/i);
	}
}
//=================== MenuIE5 =====================//
function MenuIE5(lable,action){
	this.lable = lable || null;
	this.action = action || null;
	this.menus = new Array();
	this.addMenu = function(lable,action){
		return this.menus[this.menus.length] = new MenuIE5(lable,action);
	}
	this.draw = function(parentElement,show){
		var s="",sub='';
		for( var m=0; m < this.menus.length; m++ ){
			if( this.menus[m].menus.length ){
				eval("sm_"+m+"=this.menus[m]");
				sub= 'sm_'+m+'.draw(menuSubMenus);showMenu(menuSubMenus,100,100)';
			}else sub = '';
			s += '<div nowrap="nowrap" class="menuItem'+padding(this.menus[m].lable)+'"'+
					 ' onclick="this.ce=getContextElement(this);'+this.menus[m].action+';this.done=true"'+
					 ' onmouseover="'+sub+'"'+
					 '>'+
					 lbl(this.menus[m].lable)+
					 '</div>';
		}
		if( parentElement ){
			parentElement.innerHTML = s;
			if( show )showMenu(parentElement);
		}else return s;
	}
	//Locals
	function lbl(l){return l=="-"?'':l}
	function padding(lable){return lable=="-"?' menuBar':""}
}
function showMenu(menu1,clientHeight,clientWidth,sEvent) {//debugger;
var oEvent = sEvent?eval(sEvent):event;
		menu1.contextElement=oEvent.srcElement;
		menu1.style.leftPos+=10;
		menu1.style.posLeft=oEvent.clientX-(defined(clientWidth)?oEvent.offsetX+clientWidth:10)+document.body.scrollLeft;
		if( !clientHeight )menu1.style.posTop = oEvent.clientY-10+document.body.scrollTop;////
		else menu1.style.posTop = oEvent.clientY+clientHeight-oEvent.offsetY-3;
		menu1.style.display="";
var width = document.body.offsetWidth;
var leftMax = width - menu1.offsetWidth-2+document.body.scrollLeft;
		menu1.style.posLeft = Math.min(leftMax,menu1.style.posLeft);
		menu1.style.posTop = Math.min(menu1.style.posTop,document.body.clientHeight-menu1.offsetHeight+document.body.scrollTop);
		menu1.setCapture();
		menu1.caller = oEvent.srcElement;
		if( typeof(toolTip)!='undefined' && typeof(toolTip.HideTip)=='unknown' )toolTip.HideTip();
}

function onMenuMouseOut(theMenu){
var from = event.fromElement;
var to = event.toElement;
	if( !to || to == from )return;
	if( theMenu != to.parentElement )clickMenu(theMenu,true);
	switchMenu();
}
function cloneIE5MenuEvent(){
	return unEval({srcElement:event.srcElement.uniqueID,
								 clientX:event.clientX,offsetX:event.offsetX,
								 clientY:event.clientY,offsetX:event.offsetY}
							 );
}

function switchMenu() {//debugger;
   var el=event.srcElement;
   var re = new RegExp("highlightItem","i");
   if( !el.className.match(/menuItem/i) )return;
   if( !el.className.match(re) )
      el.className += " highlightItem";
   else
      el.className = el.className.replace(re,"");
}
function clickMenu(menu1,noAction) {
	if( !noAction ) switchMenu();
  menu1.releaseCapture();
  menu1.style.display="none";
  el=event.srcElement;
  if( !el.done && !noAction && menu1!=el && el.onclick ) el.onclick();
  el.done = false;
//  if( menu1.style.display == "" && !noAction && menu1!=el && el.onclick ) el.onclick();
}
function getContextElement(el){	return (getMenuCont(el)||{}).contextElement; }
function getMenuCont(el){return getParentElementByAttrName(el,"divMenu") || getParentElementByAttrName(el,"id","menuMenus");}
//Mouse Over
function mousedown(){
var e = window.event.srcElement;
  if (e && e.down == "true")e.className += " "+e.classDown;
}
function mouseup() {
var e = window.event.srcElement;
  if (e && e.down == "true")e.className = e.className.replace(" "+e.classDown,"");
}

//************* Other stuff ******************
function onTitleBarDrag(el,contextElement,top,left){
	el = el || event.srcElement;
	if( contextElement ){
		if( el.contextElement )el.contextElement.style.display = "none";
		el.contextElement = contextElement;
		el.style.display = "";
	}
	if(!el.contextElement)return;
	if( left )el.style.posLeft = left;
	if( top )el.style.posTop = top;
	el.contextElement.style.posLeft = el.offsetLeft;
	el.contextElement.style.posTop = el.offsetTop + (el.heightReal||el.offsetHeight);
	el.contextElement.style.display = "";
	el.heightReal = el.offsetHeight;
}
